<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="movieName" label="电影名称" />
      <el-table-column prop="movieCode" label="电影编号" />
      <el-table-column prop="moviePrice" label="电影价格" />
      <el-table-column prop="movieNumber" label="电影数量" />
      <el-table-column prop="releaseDate" label="电影上映日期" />
      <el-table-column label="操作">
        <template #default="scope">
          <el-button type="primary" @click="add(scope.row)">下单</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div>
      <el-button type="primary" @click="this.$router.push('shopCar')">查看下单情况</el-button>
    </div>
  </div>

</template>

<script>
import axios from "axios";
import {ElMessage} from "element-plus";

export default {
  name: "index",
  created() {
    this.initData();
  },
  data(){
    return{
      tableData:[],
    }
  },
  methods:{
    initData(){
      let param = {
        currentPage:1,
        pageSize:20,
      }
      axios.post('api/movie/pageFindAllMovie',param).then(p=>{
        this.tableData = p.data.content;
      })
    },
    add(row){
      console.log(row);
      let date=new Date();
      let param = {
        movieName:row.movieName,
        movieCode:row.movieCode,
        price:row.moviePrice,
        num:1,
        buyDate:date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate(),
        userCode:sessionStorage.getItem("user"),
      }
      axios.post('api/MTOrder/addOrder',param).then(p=>{
        ElMessage({message: "下单成功", type: "success"})
      })
    },
  }
}
</script>

<style>

</style>